local class = reload("class")
local tcpWS = require("tcpWS")
local super = reload("tcpLS")

---@class tcpLWS : tcpLS
local this = class(super)

function this:ctor(name, ip, port)
    super.ctor(self, name, ip, port)
end

function this:launch()
    tcpWS.bind(self._name, self._ip, self._port, self)
    return self:hand()
end

---连接消息
function this:accept(ufd)
    local hand = self._hand
    hand.accept(ufd)
end

---ping消息
function this:ping(ufd)
    local hand = self._hand
    hand.ping(ufd)
end

---pong消息
function this:pong(ufd)
    local hand = self._hand
    hand.pong(ufd)
end

---进制消息
function this:recvb(ufd, mid, pack, cid)
    local hand = self._hand
    hand.recvb(ufd, mid, pack, cid)
end

---文本消息
function this:recvt(ufd, txt)
    local hand = self._hand
    hand.recvt(ufd, txt)
end

---发送消息
function this:text(ufd, text)
    tcpWS.text(self._name, ufd, text)
end

---发送消息
function this:send(ufd, mid, pack)
    local cid = self._cid + 1
    self._cid = cid
    tcpWS.send(self._name, ufd, mid, pack, cid)
    return cid
end

---回复消息
function this:reply(ufd, mid, pack, cid)
    tcpWS.send(self._name, ufd, mid, pack, cid)
end

return this
